/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vera.hibernate.dao;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import vera.hibernate.entity.BillDetail;
import vera.hibernate.entity.BillDetailId;
import vera.hibernate.util.HibernateUtil;

/**
 *
 * @author vgncr35g
 */
public class BillDetailDAO extends EntityDAO{
    public BillDetailDAO()
    {
        
    }
    
    public BillDetail getBillDetail(BillDetailId billDetailID)
    {
        Session s = HibernateUtil.openSession();
        Query q = s.getNamedQuery("getBillDetail");
        q.setInteger("billNum", billDetailID.getBillNum());
        q.setInteger("billDtlSeqNum", billDetailID.getBillDtlSeqNum());
        BillDetail billDetail = null;
        billDetail = (BillDetail) q.uniqueResult();
        s.close();
        return billDetail;
    }
    
    public List<BillDetail> getBillDetails(int billNum)
    {
        Session s = HibernateUtil.openSession();
        Query q = s.getNamedQuery("getBillDetails");
        q.setInteger("billNum", billNum);
        List<BillDetail> billDetails = null;
        billDetails = q.list();
        s.close();
        return billDetails;
    }
    
    public void deleteBillDetail(int billNum, int billDtlSeqNum)
    {
        BillDetailId billDetailId = new BillDetailId(billNum, billDtlSeqNum);
        BillDetail bd = getBillDetail(billDetailId);
        deleteEntity(bd);
    }
    public void deleteBillDetails(int billNum)
    {
        List<BillDetail> billDetails = getBillDetails(billNum);
        for(BillDetail bd : billDetails)
        {
            deleteEntity(bd);
        }
    }
    
}
